<?php
namespace bee;

class validator extends object
{ 
  /**
   * @var DOMSQLDocument
   */
  protected $DSDoc;
  /**
   * 
   * @var widget
   */
  private $widget;
  public $filter_type;
  public $filter_options;

  function __construct(widget &$widget, $filter_type = FILTER_VALIDATE_INT, array $options = array())
  { $this->__withEvents = true;
    $this->DSDoc = DOMSQLDocument::getInstance();
    dispatcher::getInstance()->addObject($this);
    $this->widget = $widget;
    $this->filter_type = $filter_type;
    $this->filter_options = $options;
      
  }
  
  function __wakeup()
  { $this->DSDoc = DOMSQLDocument::getInstance();
    dispatcher::getInstance()->addObject($this);
  }
  
  function doEvents($evt)
  { if($a=filter_var($this->widget->value, $this->filter_type, $this->filter_options)) 
    { $this->widget->class = "";
    } else  
    { $this->widget->class = "error";
      //var_dump($a, $this->widget->value);
    }
  }
  
  
  
}